package com.franklin.validation.core;

import com.franklin.validation.core.interfaces.Rule;
import com.franklin.validation.core.utils.ReflectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * Description :
 * Create By: Franklin
 * Date : 2020/6/1 15:41
 */
public abstract class AbstractRuleFactory<I,O,R> implements Rule<I,O> {

    protected Map<String,Rule> ruleMap;
    @Autowired
    protected ConfigurableApplicationContext applicationContext;

    @PostConstruct
    public void init(){
        try {
            Class ruleClass = ReflectionUtil.getSuperClassGenericType(this.getClass(), 2);
            this.ruleMap = this.applicationContext.getBeansWithAnnotation(ruleClass);
        }catch (Exception e){}
    }
}
